Challenge 4 Instructions

challenge_4
FedFundRate
More data wrangling: pivoting
Author

Shoshana Buck

Published

August 18, 2022

Code
library(tidyverse)
library(readr)
library(lubridate)
library(summarytools)

knitr::opts_chunk$set(echo = TRUE, warning=FALSE, message=FALSE)

Read in data

Code
fedfundrate <- read_csv("_data/FedFundsRate.csv",
                        show_col_types = FALSE, col_names = c("Year", "Month", "Day", "federal_funds_target_rate", "federal_funds_upper_target", "federal_funds_lower_target", "effective_federal_funds_rate", "real_GDP_percent_change", "unemployment_rate", "inflation_rate"),
                        skip=1
)
fedfundrate

Briefly describe the data

This data has been collected monthly since July 1st of 1954 and ended on march 16, 2017. There is a year-month-day combination that looks at 4 different Federal Funds Rates, while the other variables are indicators that effect the federal fund rate (inflation, unemployment and GDP changes).

Tidy Data (as needed)

Code
colnames(fedfundrate)
 [1] "Year"                         "Month"                       
 [3] "Day"                          "federal_funds_target_rate"   
 [5] "federal_funds_upper_target"   "federal_funds_lower_target"  
 [7] "effective_federal_funds_rate" "real_GDP_percent_change"     
 [9] "unemployment_rate"            "inflation_rate"              
Code
print(summarytools::dfSummary(fedfundrate,
                        varnumbers = FALSE,
                        plain.ascii  = FALSE, 
                        style        = "grid", 
                        graph.magnif = 0.70, 
                        valid.col    = FALSE),
      method = 'render',
      table.classes = 'table-condensed')

Data Frame Summary

fedfundrate

Dimensions: 904 x 10
Duplicates: 0
Variable Stats / Values Freqs (% of Valid) Graph Missing
Year [numeric]
Mean (sd) : 1986.7 (17.2)
min ≤ med ≤ max:
1954 ≤ 1987.5 ≤ 2017
IQR (CV) : 28 (0)
64 distinct values 0 (0.0%)
Month [numeric]
Mean (sd) : 6.6 (3.5)
min ≤ med ≤ max:
1 ≤ 7 ≤ 12
IQR (CV) : 6 (0.5)
12 distinct values 0 (0.0%)
Day [numeric]
Mean (sd) : 3.6 (6.8)
min ≤ med ≤ max:
1 ≤ 1 ≤ 31
IQR (CV) : 0 (1.9)
29 distinct values 0 (0.0%)
federal_funds_target_rate [numeric]
Mean (sd) : 5.7 (2.6)
min ≤ med ≤ max:
1 ≤ 5.5 ≤ 11.5
IQR (CV) : 4 (0.5)
63 distinct values 442 (48.9%)
federal_funds_upper_target [numeric]
Mean (sd) : 0.3 (0.1)
min ≤ med ≤ max:
0.2 ≤ 0.2 ≤ 1
IQR (CV) : 0 (0.5)
4 distinct values 801 (88.6%)
federal_funds_lower_target [numeric]
Mean (sd) : 0.1 (0.1)
min ≤ med ≤ max:
0 ≤ 0 ≤ 0.8
IQR (CV) : 0 (2.4)
4 distinct values 801 (88.6%)
effective_federal_funds_rate [numeric]
Mean (sd) : 4.9 (3.6)
min ≤ med ≤ max:
0.1 ≤ 4.7 ≤ 19.1
IQR (CV) : 4.2 (0.7)
466 distinct values 152 (16.8%)
real_GDP_percent_change [numeric]
Mean (sd) : 3.1 (3.6)
min ≤ med ≤ max:
-10 ≤ 3.1 ≤ 16.5
IQR (CV) : 3.5 (1.1)
113 distinct values 654 (72.3%)
unemployment_rate [numeric]
Mean (sd) : 6 (1.6)
min ≤ med ≤ max:
3.4 ≤ 5.7 ≤ 10.8
IQR (CV) : 2.1 (0.3)
71 distinct values 152 (16.8%)
inflation_rate [numeric]
Mean (sd) : 3.7 (2.6)
min ≤ med ≤ max:
0.6 ≤ 2.8 ≤ 13.6
IQR (CV) : 2.7 (0.7)
106 distinct values 194 (21.5%)

Generated by summarytools 1.0.1 (R version 4.2.1)
2022-08-28

Description of the variables

I think that the summary tools function is really great because it captures the stats/values within each variable. Additionally it displays a graph of the data from each observation. One thing that I think is interesting to point out is that

Identify variables that need to be mutated

Code
ffr_long <- fedfundrate %>% 
  pivot_longer(cols = c( "federal_funds_target_rate", "federal_funds_upper_target", "federal_funds_lower_target", "effective_federal_funds_rate", "real_GDP_percent_change", "unemployment_rate", "inflation_rate"),
               names_to = "ffr_type",
               values_to = "value",
               values_drop_na = TRUE)

ffr_long

I think that using the function pivot_longer() is a great way to tidy the data and be able to get a better understanding/read of the data.